<template>
  <!-- 随机头像 -->
  <div
    @click="$router.push('/user/' + user_address)"
    :style="randerAvatar"
    class="random-avatar"
  />
</template>

<script>
export default {
  name: "RanderAvatar",
  props: ["user_address"],
  data() {
    return {};
  },
  computed: {
    // 无头像的随机样式
    randerAvatar() {
      let addressRander = parseInt(this.user_address, 16).toString(10);
      let r = this.rand(255, addressRander.slice(4, 8));
      let g = this.rand(255, addressRander.slice(8, 12));
      let b = this.rand(255, addressRander.slice(12, 16));
      return {
        width: "100%",
        height: "100%",
        'border-radius':'50%',
        'z-index': 1,
        "background-image": `linear-gradient(to bottom right, rgb(${r},${g},${b}), rgb(${b},${r},${g}))`,
      };
    },
  },
  methods: {
    // 随机数
    rnd(seed) {
      let ret = (seed * 9301 + 49297) % 233280; //为何使用这三个数?
      return ret / 233280.0;
    },

    rand(number, seed) {
      return Math.ceil(this.rnd(seed) * number);
    },
  },
};
</script>

<style lang='less'>

</style>